<?php

namespace User\Mapper;
use User\Mapper\UserInterface;

use Base\Mapper\AbstractDbMapper;
use User\Entity\UserInterface as UserEntityInterface;
use Zend\Stdlib\Hydrator\HydratorInterface as Hydrator;

class User extends AbstractDbMapper implements UserInterface
{
    protected $tableName = 'user';
    public function __construct()
    {

    }
    
    public function findByEmail($email)
    {
        $select = $this->getSelect()->where(array('email' => $email));
        $entity = $this->select($select)->current();
        //$this->getEventManager()->trigger('find', $this, array('entity' => $entity));
        return $entity;
    }

    public function findByUsername($username)
    {
	    return NULL;
    }

    public function findById($id)
    {
        $select = $this->getSelect()
            ->where(array('user_id' => $id));

        $entity = $this->select($select)->current();
        $this->getEventManager()->trigger('find', $this, array('entity' => $entity));
        return $entity;
    }

    public function insert($entity , $tableName = null, Hydrator $hydrator = null)
    {
        $hydrator = $hydrator ? $hydrator : $this->getHydrator();
        $tableName = $this->getTableName() ? $this->getTableName() : null;
        $result = parent::insert($entity, $tableName, $hydrator);
            //$hydrator->hydrate(array('user_id' => $result->getGeneratedValue()), $entity);
            //return $result;
        var_dump($result);
        return $result;
    }

    public function update($user)
    {
	return NULL;
    }    
    public function getTableName()
    {
        return $this->tableName;
    }

    public function setTableName($tableName)
    {
        $this->tableName=$tableName;
    }
}
